var log4js = require('log4js');

log4js.configure({
  appenders: [{
    type: 'console'
  }, {
    type: 'file',
    filename: 'app.log',
    maxLogSize: 1024 * 1000,
    backups: 4,
    category: 'app'
  }],
  replaceConsole: true
});

exports.use = function(app, _level) {
  //页面请求日志, level用auto时,默认级别是WARN  
  app.use(log4js.connectLogger(log4js.getLogger("app"), {
    level: _level,
    format: ':method :url'
  }));
};

exports.logger = function(_category) {
  log4js.addAppender(log4js.appenders.file('app.log'), _category);
  return log4js.getLogger(_category);
};